package salixtest.client;

import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.googlecode.salix.client.Tree;
import com.googlecode.salix.client.TreeConfig;
import com.googlecode.salix.client.TreeItem;

/**
 * PacmanTree.
 *
 * @author Richard Richter
 */
public class PacmanTree extends Composite {
	public PacmanTree() {
		HorizontalPanel panel = new HorizontalPanel();
		panel.setStyleName("hps");

		final SimplePanel targetPanel = new SimplePanel();

		Tree tree = SalixTest.createTree(new TreeConfig()
			.setClassTreeItem("salix-item")
			.setClassTreeItemSelected("salix-item-selected")
			.setShowConnectors(false)
			.setIcons(CoolIcons.INSTANCE)
		);

		tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
			public void onSelection(SelectionEvent<TreeItem> event) {
				targetPanel.setWidget(new Label(event.getSelectedItem().getWidget().toString()));
			}
		});
		tree.draw();
		
		tree.draw();

		panel.add(tree);
		panel.add(targetPanel);

		initWidget(panel);
	}
}
